package com.sjtu.vfact.textual.tablemodel;

import java.util.ArrayList;
import java.util.List;

import javax.swing.table.AbstractTableModel;

public class VFactTableModel extends AbstractTableModel{

	private static final long serialVersionUID = -319381320642886334L;
	
	private String[] columnNames;
	private List<Object[]> data;
	
	public VFactTableModel(){
		columnNames = new String[4];
		data = new ArrayList<Object[]>();
	}

	@Override
	public int getColumnCount() {
		return columnNames.length;
	}

	@Override
	public int getRowCount() {
		return data.size();
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		return data.get(rowIndex)[columnIndex];
	}
	
	@Override
	public boolean isCellEditable(int rowIndex, int columnIndex) {
		return false;
	}
	
	@Override
	public String getColumnName(int columnIndex) {
		return columnNames[columnIndex];
	}
	
	public void setColumnNames(String[] columnNames){
		this.columnNames = columnNames;
	}
	
	public void setData(List<Object[]> data){
		this.data = data;
	}
	
	public boolean addRow(Object[] tuple) {
		boolean success = false;
		
		data.add(tuple);
		success = true;
		
		fireTableRowsInserted(data.size() - 1, data.size() - 1);
		return success;
		
	}
	
	public void clearTable(){
		data.clear();
	}

}
